import { Observer } from 'mobx-vue'
import { Component, Vue } from 'vue-property-decorator'
import CsjUpload from 'src/views/components/upload/upload.vue'
import { imagesOssPrefix } from "src/utils/ztbase"
import { getPaeClassList, addPae} from 'src/utils/axios';

@Observer
@Component({
  props: {
    clear: {
      type: Boolean,
      default: false
    }
  },
  components: {
    CsjUpload
  }
})

export default class PaeAdd extends Vue {
  isShowModel: boolean = false;
  formItem:any={
    title: "",
    media_type: "",
    class_id: "",
    content: ""
  };

  paeClassList:any = [
      
  ];
  mediaType:any =  [
      {
          label: "图片",
          value: "m"
      },
      {
        label: "视频",
        value: "v"
    },
  ];

  mounted() {
    let vm: any = this;
    vm.isShowModel = true;
    vm.getPaeClassList();
  }
  //关闭
  close() {
    let vm: any = this;
    let xwindow: any = window
    vm.isShowModel = false;
    if (!vm.clear) {
      xwindow.clearBodyStyle()
    }
    vm.$emit('close')
  }
  async confirm() {
    let vm: any = this
    let xwindow: any = window
    let param={ ...vm.formItem }
    let out:any = await addPae(param);
    if (!out.status) {
          vm.isShowModel = false;
          if (!vm.clear) {
              xwindow.clearBodyStyle()
          }
          vm.$emit('confirm')
    }else {
      vm.$Message.error(out.error.msg)
    }
  }

    //获取宣教类型
    async getPaeClassList(){
        let vm:any = this;
        let params = {
          "range": [0, 10000]
         }
         let out:any = await getPaeClassList(params);
         if(!out.status){
           vm.paeClassList=out.data.list || [];
         }
    }

  // 图片补全前缀
  imagePrefix(url, zoomScale) {
    return imagesOssPrefix(url, zoomScale)
  }

 }
 